package cn.botter.subject.domain.handler.subject.impl;

import cn.botter.subject.common.enums.SubjectInfoTypeEnum;
import cn.botter.subject.domain.entity.SubjectInfoBO;
import cn.botter.subject.domain.handler.subject.SubjectTypeHandler;
import cn.botter.subject.infra.basic.entity.SubjectBrief;
import cn.botter.subject.infra.basic.service.SubjectBriefService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class BriefTypeHandler implements SubjectTypeHandler {
    @Resource
    SubjectBriefService service;
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //简答题目的插入

        //获得info表的id即subjectId;
        String subjectAnswer = subjectInfoBO.getSubjectAnswer();
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectAnswer(subjectAnswer);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        service.add(subjectBrief);
    }

    @Override
    public SubjectInfoBO query(Integer id) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(id);
        SubjectBrief result = service.queryByCondition(subjectBrief);
        SubjectInfoBO subjectInfoBO = new SubjectInfoBO();
        subjectInfoBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectInfoBO;
    }
}
